var t = getApp().globalData.api;

Page({
    data: {
        title: "套餐详情",
        requestParams: "",
        oid: "",
        hosid: "",
        areacode: null,
        copyUrl: !1,
        showNavTab: !1,
        selectMenu: "a3",
        docutorlink: "",
        indicatorDots: !1,
        currentSwiper: 0,
        num: 1,
        originUnitParam: null,
        ifShowShartBtn: getApp().globalData.ifSharebtn,
        h5Url: "",
        neartime: [],
        selectedTime: "",
        selectedTimeStr: "",
        datum: [],
        bool: !0,
        pkgCoupon: [],
        focusFid: -1,
        docutorCopy: !1,
        windowInfo: {
            height: 0,
            width: 0
        },
        userInfo: null,
        tjlcList: [ {
            title: "选购套餐",
            img: " "
        }, {
            title: "完成预约",
            img: " "
        }, {
            title: "到院体检",
            img: " "
        }, {
            title: "获取报告",
            img: " "
        } ]
    },
    onLoad: function(t) {
        console.log(t, "packagedetails"), wx.getUserProfile && this.setData({
            canIUseGetUserProfile: !0
        });
        var a = t.oid;
 
        console.log(a);
        var e = a.toString().indexOf("new-combo-"), o = a.toString().indexOf("-n"), s = a - 0, i = a;
        0 === e ? i = a = a.toString().replace("new-combo-", "") : -1 != o && (a = a.toString().slice(o + 2));
        var n = wx.getStorageSync("openid");
      
        if (this.setData({
            options: t,
            areacode: t.areacode,
            oid: a,
            hosid: t.hosid, 
            height: wx.getSystemInfoSync().windowHeight,
            width: wx.getSystemInfoSync().windowWidth
        }), getApp().initShare(t), getApp().ifShowBtn()) {
            this.setData({
                ifShowShartBtn: getApp().ifShowBtn()
            });
            // requestParams
            var c = "".concat(t.areacode, "/").concat(t.oid);
            this.setData({
                h5Url: getApp().getDisUrl(c, {})
            }), console.log(this.data.h5Url);
        }
        var l = t.doctorOpenId;
        l && (this.setData({
            doctorOpenId: l
        }), wx.setStorageSync("doctorOpenId", l));
    },
    share: function() {},
    onPkgShareClick: function() {
        var t = this.selectComponent("#shareAlert");
        console.log(t), t.onPkgShareClick();
    },
    onShow: function() {
        this.resqustPackageDetailData(), this.bindingDoctorFans();
    },
    hideCopy: function() {
        this.setData({
            copyUrl: !this.data.copyUrl
        });
    },
    copyHospitalAdressTap: function(t) {
        wx.setClipboardData({
            data: t.currentTarget.dataset.text,
            success: function(t) {
                wx.getClipboardData({
                    success: function(t) {
                        wx.showToast({
                            title: "复制成功"
                        });
                    }
                });
            }
        });
    },
    bindingDoctorFans: function() {
        var a = wx.getStorageSync("disCode");
        if ("" != (a = a || getApp().globalData.keyTjgj.disCode) && a) {
            if (a) try {
                var e = wx.getStorageSync("openId");
                if (e) {
                    var o = {
                        disCode: a,
                        fansOpenId: e,
                        source: "2007"
                    };
                    t.postPort("saveDocFans", o, !1);
                }
            } catch (t) {}
        }
    },
    // 详情 st
    resqustPackageDetailData: function() {
        var a = this, e = {           
            areacode: this.data.areacode,
            oid: this.data.oid,
            hosid: this.data.hosid,
        };
        // comboInfo
        t.post1("/wechat/home/_findMicroPkgDetail", e, !0).then(function(t) {
            if ("1" == t.code) {
                var e = t.data;
                if (a.setData({
                    values: e
                }), a.getAppointmentTime(), e.name) {
                    //  a.getPkgState(),
                    var o = "".concat(e.name, "体检项目_套餐价格_体检网");
                    wx.setNavigationBarTitle({
                        title: o
                    }), a.setData({
                        title: o
                    });
                }
            }
        }, function(t) {
            t.data.hasOwnProperty("result") && "ERROR" == t.data.result && wx.showToast({
                title: t.data.message[0].message,
                icon: "none",
                duration: 2e3,
                mask: !0
            });
        }).then(function(t) {
            // a.requestPkgCouponList() ;
        });
    },
   
    requestPkgHistoryData: function() {
        if (this.data.userInfo) {
            var a = this, e = "";
            e = this.data.values.sourceId ? "".concat(this.data.values.microPkgHospitalDataDTO.domain, "-combo-").concat(this.data.values.sourceId) : "".concat(this.data.values.microPkgHospitalDataDTO.domain, "-combo-n").concat(this.data.values.id);
            var o = {
                areacode: this.data.areacode,
                code: e,
                memberId: this.data.userInfo.id,
                foreignId: this.data.values.id,
                browseType: "2",
                browseName: this.data.values.name,
                picUrl: this.data.values.imgList[0],
                source: getApp().globalData.appInfo.zkSource
            };
            t.postPort("getFavoriteMemberBehavior", o, !1).then(function(t) {
                "SUCCESS" == t.result && a.setData({
                    focusFid: t.values
                });
            }, function(t) {});
        }
    },
    requestPkgCouponList: function() {
        var a = this, e = {
            appSource: getApp().globalData.appInfo.zkSource,
            pkgId: this.data.values.id
        };
        t.postPort("listCanDrawCouponByPkgId", e, !1).then(function(t) {
            "SUCCESS" == t.result && Array.isArray(t.values) && a.setData({
                pkgCoupon: t.values
            });
        }, function(t) {});
    },
    goHosDiscountTap: function() {
        this.selectComponent("#hostpitalDiscount").show();
    },
    getCoupon: function(a) {
        var e = a.detail.couponid, o = this;
        t.getPort("information", !0).then(function(t) {
            "SUCCESS" == t.result && o.goDrawCoupon(e);
        }, function(t) {
            o.goLogin();
        });
    },
    goDrawCoupon: function(a) {
        var e = this, o = {
            appSource: getApp().globalData.appInfo.zkSource,
            couponId: a
        };
        t.postPort("getDiscountsNum", o, !0).then(function(t) {
            if ("SUCCESS" == t.result) {
                wx.showToast({
                    icon: "none",
                    title: "领取成功,请尽快使用"
                });
                var o = e.data.pkgCoupon;
                o.forEach(function(t) {
                    t.id == a && (t.ifDraw = !1);
                }), e.setData({
                    pkgCoupon: o
                });
            }
        }, function(t) {
            t.data.message[0].message && wx.showToast({
                icon: "none",
                title: t.data.message[0].message
            });
        });
    },
    goLogin: function() {
        wx.navigateTo({
            url: "/pages/login/login"
        });
    },
    reduce: function() {
        1 != this.data.num ? this.setData({
            num: --this.data.num
        }) : wx.showToast({
            title: "请至少保留一位体检人",
            icon: "none",
            duration: 2e3,
            mask: !0
        });
    },
    add: function() {
        10 != this.data.num ? "8064" != this.data.values.packageType && this.data.values.packageType || this.setData({
            num: ++this.data.num
        }) : wx.showToast({
            title: "超出购买上限",
            icon: "none",
            duration: 2e3,
            mask: !0
        });
    },
    menuTap: function(t) {
        var a = this, e = t.currentTarget.dataset.muneid;
        this.setData({
            selectMenu: e,
            bool: !1
        });
        var o = wx.createSelectorQuery().in(this);
        o.selectViewport().scrollOffset(), o.select("#" + e).boundingClientRect(), o.exec(function(t) {
            var e = t[0].scrollTop + t[1].top - 50;
            wx.pageScrollTo({
                scrollTop: e,
                duration: 300,
                success: function(t) {},
                fail: function() {},
                complete: function(t) {
                    a.setData({
                        bool: !0
                    });
                }
            });
        });
    },
    calendarTap: function(t) {
        this.selectComponent("#packageDate").show();
    },
    getChildDate: function(t) {
        this.setData({
            selectedTime: t.detail.strmonth + t.detail.strday,
            selectedTimeStr: t.detail.strTime
        });
    },
    getAppointmentTime: function() {
        var t = [ "零", "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二" ], a = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"), e = this.data.values.appointDate;
        if (console.log(e), e.length > 0) {
            for (var o = [], s = 0; s < e.length && !(s > 3); s++) {
                var i = {}, n = t[parseInt(e[s].split("-")[1])] + "月", r = e[s].split("-")[2], c = a[new Date(e[s]).getDay()];
                i.month = n, i.day = r, i.week = c, o.push(i);
            }
            this.setData({
                neartime: o
            });
        }
    },
    getPkgState: function() {
        var t = !1;
        t = "4" != this.data.values.microPkgHospitalDataDTO.status || !this.data.values.microPkgHospitalDataDTO.openStatus;
        var a = !1;
        a = "3" == this.data.values.microPkgHospitalDataDTO.statusappoint, this.setData({
            tcFull: a,
            tcShelves: t
        });
    },
    
    
    allTjtcTap: function() {
        var t = this.data.values.microPkgHospitalDataDTO.domain, a = this.data.values.microPkgHospitalDataDTO.areacode, e = "/pages/hospitalinfo/hospitalinfo?domain=".concat(t, "&areacode=").concat(a);
        getApp().pushPage(e);
    },
    jxtcTap: function(t) {
        var a = t.currentTarget.dataset.pkginfo, e = "";
        e = a.hasOwnProperty("sourceId") ? a.domain + "-combo-" + a.sourceId : a.id;
        var o = "/pages/packagedetails/packagedetails?requestParams=".concat(e, "&areacode=").concat(a.areacode);
        getApp().pushPage(o);
    },
    allTjyyTap: function() {
        wx.switchTab({
            url: "/pages/hospital-list/hospital-list"
        });
    },
    hospitalDetailTap: function(t) {
        var a = t.currentTarget.dataset.info, e = "/pages/hospitalinfo/hospitalinfo?domain=".concat(a.domain, "&areacode=").concat(a.areacode);
        getApp().pushPage(e);
    },
    imgTap: function(t) {
        for (var a = t.currentTarget.dataset.src, e = t.currentTarget.dataset.list, o = [], s = 0; s < e.length; s++) {
            var i = e[s];
            o.push(i.scaleUrl);
        }
        wx.previewImage({
            current: a,
            urls: o
        });
    },
    swiperChange: function(t) {
        this.setData({
            currentSwiper: t.detail.current
        });
    },
 
    openInfoTap: function() {
        this.packageAd = this.selectComponent("#packageAd"), this.packageAd.show();
    },
    pkgCollectTap: function() {
        var a = this;
        if (wx.getStorageSync("token")) {
            var e = this.data.focusFid;
            if (e > 0) {
                var o = {
                    rest: e
                };
                t.delPort("deleteMemFavoriteGdsById", o, !0).then(function(t) {
                    "SUCCESS" == t.result && t.values && (a.setData({
                        focusFid: 0
                    }), wx.showToast({
                        icon: "none",
                        title: "已取消收藏"
                    }));
                }, function(t) {
                    t.data.hasOwnProperty("result") && "ERROR" == t.data.result && wx.showToast({
                        title: t.data.message[0].message,
                        icon: "none",
                        duration: 2e3,
                        mask: !0
                    });
                });
            } else {
                var s = {
                    rest: this.data.values.id
                };
                t.getPort("saveOrUpdateMemFavoriteGds", s, !0).then(function(t) {
                    "SUCCESS" == t.result && t.values > 0 && (a.setData({
                        focusFid: t.values
                    }), wx.showToast({
                        icon: "none",
                        title: "收藏成功"
                    }));
                }, function(t) {
                    t.data.hasOwnProperty("result") && "ERROR" == t.data.result && wx.showToast({
                        title: t.data.message[0].message,
                        icon: "none",
                        duration: 2e3,
                        mask: !0
                    });
                });
            }
        } else wx.navigateTo({
            url: "/pages/login/login"
        });
    },
    bannerTap: function(t) {
        var a = t.currentTarget.dataset.src, e = t.currentTarget.dataset.list;
        wx.previewImage({
            current: a,
            urls: e
        });
    },
    goHospital: function() {
        var t = this.data.values.hosinfo.domain, a = this.data.values.hosinfo.areacode, e = "/pages/hospitalinfo/hospitalinfo?domain=".concat(t, "&areacode=").concat(a);
        getApp().pushPage(e);
    },
    rebateBuyClick: function() {
        this.buyPkgTap();
    },
    addItem: function() {
        getApp().globalData.appInfo.pushMsgInfo.isOpen ? this.subscribeMessage() : this.enterOrderInfo("addItem");
    },
    // 预约
    buyPkgTap: function() {
        // st  一直报错
        // getApp().globalData.appInfo.pushMsgInfo.isOpen=1;
        // console.log(getApp().globalData.appInfo);
        // this.enterOrderInfo()
        getApp().globalData.appInfo.pushMsgInfo.isOpen ? this.subscribeMessage() : this.enterOrderInfo();
    },
 
    enterOrderInfo: function(a) {
        var e = this.data.selectedTimeStr, o = this.data.values.id, s = this.data.num, i = this.data.values.orgId;
        var openid = wx.getStorageSync('openid');
        t.post1("wechat/Member/getUserInfo", {
            openid: openid
        }).then(function(t) { 
            var n = "";
            n = "addItem" == a ? "/subpackages/order/pages/item?orgId=" + i + "&goodsid=" + o + "&setNumber=" + s + "&seldate=" + e : "/pages/order/place-order/place-order?goodsid=" + o + "&setNumber=" + s + "&seldate=" + e, 
            getApp().pushPage(n);
        }, function(t) {
            wx.navigateTo({
                url: "/pages/login/login"
            });
        });
    },
    subscribeMessage: function() {
        console.log(11111);
        var t = this, a = getApp().globalData.appInfo.pushMsgInfo.tmplIdsArr;
        wx.getSetting({
            withSubscriptions: !0,
            success: function(e) {
                e.subscriptionsSetting.mainSwitch ? null != e.subscriptionsSetting.itemSettings ? t.enterOrderInfo() : wx.requestSubscribeMessage({
                    tmplIds: a,
                    success: function(t) {},
                    fail: function(t) {},
                    complete: function(a) {
                        t.enterOrderInfo();
                    }
                }) : t.enterOrderInfo();
            },
            fail: function(a) {
                t.enterOrderInfo();
            }
        });
    },
    onlineTap: function() {
        var t = {
            pagePath: "/pages/packagedetails/packagedetails",
            pkgId: this.data.values.id
        };
        getApp().onlineKeFuTap(t);
    },
    navBackTap: function() {
        getCurrentPages().length > 1 ? wx.navigateBack({
            delta: 1
        }) : wx.switchTab({
            url: "/pages/homepages/homepages"
        });
    },
    onShareAppMessage: function() {
        if (console.log(this.data.options), getApp().ifShowBtn()) {
            var t = wx.getStorageSync("disCode"), a = {
                disCode: t = t || getApp().globalData.keyTjgj.disCode,
                requestParams: this.data.options.requestParams,
                areacode: this.data.options.areacode
            }, e = "";
            for (var o in a) a[o] && (e = e.length > 1 ? "".concat(e, "&").concat(o, "=").concat(a[o]) : "".concat(o, "=").concat(a[o]));
            var s = "/pages/packagedetails/packagedetails?".concat(e);
            return console.log(s), {
                title: "点击查看您的体检方案",
                path: s,
                imageUrl: "/image/share/icon_share_cart_tj.jpg"
            };
        }
        var i = this.data.values.name;
        if (i) return {
            title: i
        };
    }
});